/*
 * @Author: shawnXiao
 * @Date: 2021-12-18 21:18:34
 * @LastEditTime: 2021-12-19 20:36:56
 * @FilePath: /vue3-vite2-ts-antdv/src/store/index.ts
 */
// @/store/index.ts
// import { createStore } from 'vuex'

// export default createStore({
//   state: {},
//   mutations: {},
//   actions: {},
//   modules: {}
// });
// @description 导入所有 vuex 模块，自动加入namespaced:true，用于解决vuex命名冲突，请勿修改。

import { createStore } from 'vuex'
import { State } from '@/types/store'

const modulesFiles = import.meta.globEager('./modules/*.ts')
const pathList: string[] = []

for (const path in modulesFiles) {
  pathList.push(path)
}

const modules = pathList.reduce((modules: any, modulePath: string) => {
  const moduleName = modulePath.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
  const value = modulesFiles[modulePath]
  modules[moduleName] = value.default
  return modules
}, {})

const store = createStore<State>({
  modules
})

export default store